#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void get_memory(char **p, int num)
{
	*p = (char *)malloc(num);
}

int main()
{
	char *str = NULL;
	
	get_memory(&str, 100);
	strcpy(str, "xiaozhi");
	
	printf("%s\n", str); // xiaozhi
}

#if 0
/*
 * intel
 */
0000000000001189 <get_memory>:
    1189:	f3 0f 1e fa          	endbr64 
    118d:	55                   	push   %rbp
    118e:	48 89 e5             	mov    %rsp,%rbp
    1191:	48 83 ec 10          	sub    $0x10,%rsp
    1195:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    1199:	89 75 f4             	mov    %esi,-0xc(%rbp)
    119c:	8b 45 f4             	mov    -0xc(%rbp),%eax
    119f:	48 98                	cltq   
    11a1:	48 89 c7             	mov    %rax,%rdi
    11a4:	e8 e7 fe ff ff       	callq  1090 <malloc@plt>
    11a9:	48 89 c2             	mov    %rax,%rdx
    11ac:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    11b0:	48 89 10             	mov    %rdx,(%rax)
    11b3:	90                   	nop
    11b4:	c9                   	leaveq 
    11b5:	c3                   	retq   

00000000000011b6 <main>:
    11b6:	f3 0f 1e fa          	endbr64 
    11ba:	55                   	push   %rbp
    11bb:	48 89 e5             	mov    %rsp,%rbp
    11be:	48 83 ec 10          	sub    $0x10,%rsp
    11c2:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11c9:	00 00 
    11cb:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    11cf:	31 c0                	xor    %eax,%eax
    11d1:	48 c7 45 f0 00 00 00 	movq   $0x0,-0x10(%rbp)
    11d8:	00 
    11d9:	48 8d 45 f0          	lea    -0x10(%rbp),%rax
    11dd:	be 64 00 00 00       	mov    $0x64,%esi
    11e2:	48 89 c7             	mov    %rax,%rdi
    11e5:	e8 9f ff ff ff       	callq  1189 <get_memory>
    11ea:	48 8b 45 f0          	mov    -0x10(%rbp),%rax
    11ee:	48 ba 78 69 61 6f 7a 	movabs $0x69687a6f616978,%rdx
    11f5:	68 69 00 
    11f8:	48 89 10             	mov    %rdx,(%rax)
    11fb:	48 8b 45 f0          	mov    -0x10(%rbp),%rax
    11ff:	48 89 c7             	mov    %rax,%rdi
    1202:	e8 69 fe ff ff       	callq  1070 <puts@plt>
    1207:	b8 00 00 00 00       	mov    $0x0,%eax
    120c:	48 8b 4d f8          	mov    -0x8(%rbp),%rcx
    1210:	64 48 33 0c 25 28 00 	xor    %fs:0x28,%rcx
    1217:	00 00 
    1219:	74 05                	je     1220 <main+0x6a>
    121b:	e8 60 fe ff ff       	callq  1080 <__stack_chk_fail@plt>
    1220:	c9                   	leaveq 
    1221:	c3                   	retq   
    1222:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    1229:	00 00 00 
    122c:	0f 1f 40 00          	nopl   0x0(%rax)

/*
 * arm
 */
000000000040064c <get_memory>:
  40064c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400650:	910003fd 	mov	x29, sp
  400654:	f9000fa0 	str	x0, [x29, #24]
  400658:	b90017a1 	str	w1, [x29, #20]
  40065c:	b98017a0 	ldrsw	x0, [x29, #20]
  400660:	97ffffa8 	bl	400500 <malloc@plt>
  400664:	aa0003e1 	mov	x1, x0
  400668:	f9400fa0 	ldr	x0, [x29, #24]
  40066c:	f9000001 	str	x1, [x0]
  400670:	d503201f 	nop
  400674:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400678:	d65f03c0 	ret

000000000040067c <main>:
  40067c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  400680:	910003fd 	mov	x29, sp
  400684:	f9000fbf 	str	xzr, [x29, #24]
  400688:	910063a0 	add	x0, x29, #0x18
  40068c:	52800c81 	mov	w1, #0x64                  	// #100
  400690:	97ffffef 	bl	40064c <get_memory>
  400694:	f9400fa0 	ldr	x0, [x29, #24]
  400698:	90000001 	adrp	x1, 400000 <_init-0x4c0>
  40069c:	911dc021 	add	x1, x1, #0x770
  4006a0:	f9400021 	ldr	x1, [x1]
  4006a4:	f9000001 	str	x1, [x0]
  4006a8:	f9400fa0 	ldr	x0, [x29, #24]
  4006ac:	97ffffa5 	bl	400540 <puts@plt>
  4006b0:	52800000 	mov	w0, #0x0                   	// #0
  4006b4:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4006b8:	d65f03c0 	ret
  4006bc:	00000000 	.inst	0x00000000 ; undefined


#endif

